package shangke;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class tset {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        //面向对象和是实例化对象
        goodsCH g=new goodsCH();
        g.setPrice(150);
        //通过反射手段获取类的对象
        Class cla=Class.forName("shangke.goodsCH");
     Field field=   cla.getField("price");
;     //使用类模板的构造方法创建实例对象
        Constructor constructor=cla.getConstructor();
        Object obj=constructor.newInstance();
        field.setInt(obj,100);
        Method method=  cla.getMethod("test",int.class);
    int num=(int)  method.invoke(obj,23);
int count= field.getInt(obj);
System.out.println(count);
System.out.println(num);
System.out.println(g.getPrice());
    }
}
